/**
 * SCSS混入函数
 */

// 清除浮动
@mixin clearfix {
  &::after {
    content: '';
    display: table;
    clear: both;
  }
}

// 文本省略
@mixin ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

// 多行文本省略
@mixin ellipsis-multiline($lines: 2) {
  display: -webkit-box;
  -webkit-line-clamp: $lines;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

// 居中对齐
@mixin center {
  display: flex;
  align-items: center;
  justify-content: center;
}

// 垂直居中
@mixin vertical-center {
  display: flex;
  align-items: center;
}

// 水平居中
@mixin horizontal-center {
  display: flex;
  justify-content: center;
}

// 绝对定位居中
@mixin absolute-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

// 响应式断点
@mixin respond-to($breakpoint) {
  @if $breakpoint == xs {
    @media (max-width: #{$breakpoint-xs - 1px}) {
      @content;
    }
  }
  @if $breakpoint == sm {
    @media (min-width: #{$breakpoint-xs}) and (max-width: #{$breakpoint-sm - 1px}) {
      @content;
    }
  }
  @if $breakpoint == md {
    @media (min-width: #{$breakpoint-sm}) and (max-width: #{$breakpoint-md - 1px}) {
      @content;
    }
  }
  @if $breakpoint == lg {
    @media (min-width: #{$breakpoint-md}) and (max-width: #{$breakpoint-lg - 1px}) {
      @content;
    }
  }
  @if $breakpoint == xl {
    @media (min-width: #{$breakpoint-lg}) {
      @content;
    }
  }
}

// 最小宽度断点
@mixin min-width($width) {
  @media (min-width: $width) {
    @content;
  }
}

// 最大宽度断点
@mixin max-width($width) {
  @media (max-width: $width) {
    @content;
  }
}

// 按钮样式
@mixin button-variant($color, $background, $border) {
  color: $color;
  background-color: $background;
  border-color: $border;
  
  &:hover,
  &:focus {
    color: $color;
    background-color: lighten($background, 10%);
    border-color: lighten($border, 10%);
  }
  
  &:active {
    color: $color;
    background-color: darken($background, 10%);
    border-color: darken($border, 10%);
  }
  
  &.is-disabled,
  &.is-disabled:hover,
  &.is-disabled:focus,
  &.is-disabled:active {
    color: $text-color-placeholder;
    background-color: $bg-color-light;
    border-color: $border-color-lighter;
  }
}

// 卡片样式
@mixin card {
  background: $bg-color;
  border: 1px solid $border-color-lighter;
  border-radius: $border-radius-base;
  box-shadow: $box-shadow-light;
  transition: box-shadow 0.3s;
  
  &:hover {
    box-shadow: $box-shadow-base;
  }
}

// 输入框样式
@mixin input {
  display: inline-block;
  width: 100%;
  padding: 8px 12px;
  font-size: $font-size-base;
  line-height: $line-height-base;
  color: $text-color-primary;
  background-color: $bg-color;
  border: 1px solid $border-color-base;
  border-radius: $border-radius-base;
  transition: border-color 0.3s, box-shadow 0.3s;
  
  &:focus {
    outline: none;
    border-color: $color-primary;
    box-shadow: 0 0 0 2px rgba($color-primary, 0.2);
  }
  
  &::placeholder {
    color: $text-color-placeholder;
  }
  
  &:disabled {
    background-color: $bg-color-light;
    color: $text-color-placeholder;
    cursor: not-allowed;
  }
}

// 滚动条样式
@mixin scrollbar($width: 6px, $track-color: $border-color-lighter, $thumb-color: $border-color-base) {
  &::-webkit-scrollbar {
    width: $width;
    height: $width;
  }
  
  &::-webkit-scrollbar-track {
    background: $track-color;
    border-radius: $width / 2;
  }
  
  &::-webkit-scrollbar-thumb {
    background: $thumb-color;
    border-radius: $width / 2;
    
    &:hover {
      background: darken($thumb-color, 10%);
    }
  }
}

// 加载动画
@mixin loading-spinner($size: 20px, $color: $color-primary) {
  display: inline-block;
  width: $size;
  height: $size;
  border: 2px solid rgba($color, 0.3);
  border-radius: 50%;
  border-top-color: $color;
  animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

// 渐变背景
@mixin gradient-background($start-color, $end-color, $direction: to right) {
  background: linear-gradient($direction, $start-color, $end-color);
}

// 文本渐变
@mixin gradient-text($start-color, $end-color, $direction: to right) {
  background: linear-gradient($direction, $start-color, $end-color);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

// 阴影效果
@mixin box-shadow($shadow...) {
  box-shadow: $shadow;
}

// 过渡动画
@mixin transition($property: all, $duration: 0.3s, $timing-function: ease) {
  transition: $property $duration $timing-function;
}

// 变换
@mixin transform($transforms...) {
  transform: $transforms;
}

// 用户选择
@mixin user-select($select: none) {
  -webkit-user-select: $select;
  -moz-user-select: $select;
  -ms-user-select: $select;
  user-select: $select;
}

// 占位符样式
@mixin placeholder {
  &::-webkit-input-placeholder {
    @content;
  }
  &:-moz-placeholder {
    @content;
  }
  &::-moz-placeholder {
    @content;
  }
  &:-ms-input-placeholder {
    @content;
  }
}
